package com.example.factory;

import com.example.model.SsopTag;
import com.example.strategy.SsopTagStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author leiliang
 * @version 1.0
 * @Description
 * @date 2022/6/13 15:12
 */
@Service
public class SsopTagContext {

    @Autowired
    private final Map<String, SsopTagStrategy> strategyMap = new ConcurrentHashMap<>();

    public SsopTagContext(Map<String, SsopTagStrategy> strategyMap) {
        this.strategyMap.clear();
        strategyMap.forEach((k, v)-> this.strategyMap.put(k, v));
    }


    public SsopTag getResource(SsopTag ssopTag){
        return strategyMap.get(ssopTag.getTagGroup()).handleData(ssopTag);
    }

}
